<template>
    <div id="main">
        <div class="bar">
            <div class="left">
                我的课程列表
            </div>
            <div class="right">
                <!-- <el-button type="success" size="mini"  @click="addMenu"> <i class="el-icon-plus"></i> 添加课程</el-button> -->
            </div>
        </div>
        <div class="table">
            <el-table
                :data="tableData"
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                border
                default-expand-all
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column
                prop="id"
                label="ID"
                align="center"
                sortable
               >
                </el-table-column>

               
                <!-- <el-table-column
                
                align="center"
                label="课程分类">
                    <template slot-scope="scope">
                        {{ scope.row.fid | SetClassName }}
                    </template>
                </el-table-column> -->

                <el-table-column
                prop="name"
                align="center"
                label="课程名称">
                    
                </el-table-column>

                <el-table-column
                prop="classnum"
                align="center"
                label="试卷数">
                    
                </el-table-column>

                <el-table-column
                prop="peoplenum"
                align="center"
                label="学习人数">
                    
                </el-table-column>


                <!-- <el-table-column
               
                align="center"
                label="状态">
                    <template slot-scope="scope">
                        <el-button :type="scope.row.status == 1 ? 'success':'danger' " size="mini" @click="editMenu(scope.row)">
                            {{ scope.row.status == 1 ? "开启":"关闭"}}
                        </el-button>
                    </template>
                </el-table-column> -->

                <el-table-column
               
                align="center"
                label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="editMenu(scope.row)">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- dialog -->
        <ke-dialog :DialogData="DialogData" :FormData="FormData" :className="className" @update="getSchoolList"></ke-dialog>
    </div>
</template>

<script>
    let self
    import KeDialog from "@/components/dialog/KeDialog"
    export default {
        data() {
            return {
                tableData: [],
                DialogData: {
                    title: "",
                    show: false,
                },
                FormData: {},
                className: [],
            }
        },
        components: {
            KeDialog,
        },
        computed: {
            token() {
                return localStorage.token; 
            }
        },
        filters: {
            SetClassName: function(value) {
                let str = ""
                self.className.forEach( el => {
                    if (el.id == value) {
                        str = el.name
                        console.log(str);
                        
                    }
                })
                return str
            },
        },
        beforeCreate () {
            self = this;
        },
        mounted() {
            this.getSchoolList()
            
        },
        methods: {
            // 匹配课程分类名称
            async getClassname() {
                let res = await this.$axios.post("/admin/website/classification", { token: this.token })

                if (res.data.data) {
                    this.className = res.data.data
                    
                }
            },
            // 获取网站信息
            async getSchoolList() {
                let res = await this.$axios.post("/admin/website/agentclassshow", { token: this.token })
                 console.log(res);
                if(res.data.code == 200) {
                    this.tableData = res.data.data
                    this.getClassname()
                }
                
            },
            // 编辑菜单
            editMenu( user ) {
                
            },
            // 添加菜单
            addMenu() {
                this.DialogData = {
                    show: true,
                    title: "添加课程",
                    add: true,
                    edit: false
                }
                this.FormData = {}
            },
            // 菜单状态改变
            async changeStatus( id ) {
               
            },
        },
    }
</script>

<style lang="scss" scoped>
 #main {
     width: 100%;
     box-sizing: border-box;
     .bar {
         width: 100%;
         font-weight: bold;
         display: flex;
         justify-content: space-between;
         height: 40px;
         line-height: 40px;
         border-bottom: 1px solid #aaa;
     }
     .table {
         margin-top: 20px;
     }
     .pic {
         width: 40px;
         height: 40px;
         display: block;
     }
 }
</style>